package com.lab.project.classroom.controller;
import com.lab.framework.web.controller.BaseController;
import com.lab.framework.web.domain.AjaxResult;
import com.lab.framework.web.page.TableDataInfo;
import com.lab.project.classroom.domain.SchoolClassroomEntity;
import com.lab.project.classroom.service.ISchoolClassroomService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学校教室controller
 * @author 黄晏凯
 */
@RestController
@RequestMapping("/demo/classroom")
@AllArgsConstructor
public class ClassroomController extends BaseController {
    private ISchoolClassroomService schoolClassroomService;

    /**
     * 添加教室
     * @param schoolClassroomEntity
     * @return 操作结果
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SchoolClassroomEntity schoolClassroomEntity){
        return toAjax(schoolClassroomService.addClassroom(schoolClassroomEntity));
    }

    /**
     * 查询教室信息
     * @param schoolClassroomEntity
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo listClassroom(SchoolClassroomEntity schoolClassroomEntity){
        startPage();
        List<SchoolClassroomEntity> list = schoolClassroomService.listClassroom(schoolClassroomEntity);
        return getDataTable(list);
    }

    /**
     *通过id查找教室
     * @param id
     * @return AjaxResult
     */
    @GetMapping("/getInfo/{id}")
    public AjaxResult getSchoolClassroomInfoById(@PathVariable Long id){
        return AjaxResult.success(schoolClassroomService.getSchoolClassroomInfoById(id));
    }

    /**
     * 修改教室信息
     * @return 操作结果
     */
    @PutMapping("/edit")
    public AjaxResult updateSchoolClassroom(@RequestBody SchoolClassroomEntity schoolClassroomEntity){
        return toAjax(schoolClassroomService.updateSchoolClassroom(schoolClassroomEntity));
    }

    /**
     *删除教室
     * @param ids
     * @return 操作结果
     */
    @DeleteMapping("/delete/{ids}")
    public AjaxResult deleteSchoolClassroomByIds(@PathVariable Long[] ids){
        return toAjax(schoolClassroomService.deleteSchoolClassroomByIds(ids));

    }
}
